package top.heue.epro.service;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import top.heue.epro.bean.ConfigBean;
import top.heue.epro.util.ConfigUtil;
import top.heue.epro.util.WindowUtil;

public class WindowService extends Service {

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public IBinder onBind(Intent p1) {
        return null;
    }

    private WindowUtil windowUtil;
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        ConfigBean config = ConfigUtil.readUtil(this);
        if(windowUtil != null && WindowUtil.isShowing)
            windowUtil.close();
        assert config != null;
        windowUtil = new WindowUtil(this, config.getSrc(), config.getAlpha());
        windowUtil.show();
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        windowUtil.close();
    }
}
